﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ESAM_Assignment_3
{
    public partial class DeleteComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Eric
            Response.CacheControl = "no-cache";
            if (!(bool)Session[Common.ESAM_LOGIN])
            {
                Response.Redirect("Default.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    int CommentID = Convert.ToInt32(Request.QueryString["CommentID"]);
                    lblCommentID.Text = CommentID.ToString();

                    //eric
                    CommentClass myComment = CommentClass.GetComment(CommentID);

                    if (myComment.Username != Session[Common.ESAM_USERNAME].ToString())
                    {
                        Response.Redirect("ListComments.aspx");
                    }
                    else
                    {

                        bool status = CommentClass.DeleteComment(CommentID);

                        if (status)
                        {
                            lblStatus.ForeColor = System.Drawing.Color.Blue;
                            lblStatus.Text = "Success. Comment has been deleted.";

                        }
                        else
                        {
                            lblStatus.ForeColor = System.Drawing.Color.Red;
                            lblStatus.Text = "Error! Comment has been deleted.";
                        }
                    }
                }
            }
        }
    }
}